package com.elong.businesstravel.base.baidusdk.map;

import android.content.Context;
import android.widget.Toast;

import com.android.support.jhf.handlerui.HandlerToastUI;
import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.MKGeneralListener;
import com.baidu.mapapi.map.MKEvent;

/**
 * 初始化百度地图，在application中
 * 
 * @author hongfeijia
 * 
 */
public class InitBaiduMap {

	private static final String strKey = "NuLA5j8nczQaEfMuMxRFkP2M";// 正式签名
	//private static final String strKey = "1MQsEbC2pKk9amPcNkew1aHG";// 公司测试
//	public static final String strKey = "dWbg6xP6XiT6Nr5TWgbmf2I7";// 家里测试
	private BMapManager mBMapManager = null;

	private Context mContext;

	static {
//		System.loadLibrary("BaiduMapSDK_v2_4_0");
//		System.loadLibrary("locSDK4b");
	}

	public InitBaiduMap(Context context) {
		mContext = context;
	}

	public void initEngineManager() {
		if (mBMapManager == null) {
			mBMapManager = new BMapManager(mContext);
		}
		if (!mBMapManager.init( new MyGeneralListener(mContext))) {
//			HandlerToastUI.getHandlerToastUI(mContext, "BMapManager  初始化错误!");
		}
	}

	public BMapManager getBMapManager() {
		return mBMapManager;
	}

	// 常用事件监听，用来处理通常的网络错误，授权验证错误等
	private static class MyGeneralListener implements MKGeneralListener {

		private Context mContext;

		public MyGeneralListener(Context context) {
			mContext = context;
		}

		@Override
		public void onGetNetworkState(int iError) {
			if (iError == MKEvent.ERROR_NETWORK_CONNECT) {
//				HandlerToastUI.getHandlerToastUI(mContext, "您的网络出错啦！");
			} else if (iError == MKEvent.ERROR_NETWORK_DATA) {
//				HandlerToastUI.getHandlerToastUI(mContext, "输入正确的检索条件！");
			}
		}

		@Override
		public void onGetPermissionState(int iError) {
			if (iError == MKEvent.ERROR_PERMISSION_DENIED) {
				// 授权Key错误：
//				HandlerToastUI.getHandlerToastUI(mContext,
//						"请在 DemoApplication.java文件输入正确的授权Key！");
			}
		}
	}
}
